"""
缓存接口定义
===========
定义缓存操作的抽象接口，支持Redis、Memcached等多种缓存实现
"""

from abc import ABC, abstractmethod
from typing import Any, Optional, List, Dict, Union
from datetime import timedelta


class CacheInterface(ABC):
    """缓存接口定义"""
    
    @abstractmethod
    async def connect(self) -> bool:
        """建立缓存连接"""
        pass
    
    @abstractmethod
    async def disconnect(self) -> bool:
        """断开缓存连接"""
        pass
    
    @abstractmethod
    async def get(self, key: str) -> Optional[Any]:
        """获取缓存值"""
        pass
    
    @abstractmethod
    async def set(self, key: str, value: Any, expire: Optional[Union[int, timedelta]] = None) -> bool:
        """设置缓存值"""
        pass
    
    @abstractmethod
    async def delete(self, key: str) -> bool:
        """删除缓存"""
        pass
    
    @abstractmethod
    async def exists(self, key: str) -> bool:
        """检查键是否存在"""
        pass
    
    @abstractmethod
    async def expire(self, key: str, seconds: Union[int, timedelta]) -> bool:
        """设置过期时间"""
        pass
    
    @abstractmethod
    async def ttl(self, key: str) -> int:
        """获取剩余生存时间"""
        pass
    
    @abstractmethod
    async def get_many(self, keys: List[str]) -> Dict[str, Any]:
        """批量获取"""
        pass
    
    @abstractmethod
    async def set_many(self, mapping: Dict[str, Any], expire: Optional[Union[int, timedelta]] = None) -> bool:
        """批量设置"""
        pass
    
    @abstractmethod
    async def delete_many(self, keys: List[str]) -> int:
        """批量删除，返回删除的数量"""
        pass
    
    @abstractmethod
    async def increment(self, key: str, amount: int = 1) -> int:
        """递增计数器"""
        pass
    
    @abstractmethod
    async def decrement(self, key: str, amount: int = 1) -> int:
        """递减计数器"""
        pass
    
    @abstractmethod
    async def keys(self, pattern: str = "*") -> List[str]:
        """获取匹配的键列表"""
        pass
    
    @abstractmethod
    async def clear(self) -> bool:
        """清空所有缓存"""
        pass
    
    @abstractmethod
    async def health_check(self) -> Dict[str, Any]:
        """健康检查"""
        pass
